package com.cz.second.kill.controller;

import com.cz.second.kill.service.ISecondKill;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>秒杀控制器</p>
 * <p>
 * <pre>
 * @author gitamacai
 * @date 2019/12/4 18:14
 * </pre>
 */
@RestController
@RequestMapping("/api/kill")
@Api("一个简单栗子")
public class SecondKillController {
    @Autowired
    @Qualifier("mysqlSecondKillImpl")
    private ISecondKill mysqlSecondKill;
    @Autowired
    @Qualifier("redisSecondKillImpl")
    private ISecondKill redisSecondKill;


    @RequestMapping(value = "/mysqlSecondKill", method = RequestMethod.GET)
    public String mysqlSecondKill(String uid) {
        Integer kill = mysqlSecondKill.kill(uid);
        if (kill == 0) {
            return "使用mysql----秒杀活动结束了，很遗憾你没有抢到";
        }

        return kill.toString();
    }

    @RequestMapping(value = "/redisSecondKill", method = RequestMethod.GET)
    public String redisSecondKill(String uid) {
        Integer kill = redisSecondKill.kill(uid);
        if (kill == 0) {
            return "使用redis-----秒杀活动结束了，很遗憾你没有抢到";
        }
        return kill.toString();
    }

}
